<?php

namespace App\Admin\Controllers;

use App\Yuyue;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class YuyueController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '预约列表';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Yuyue());

        $grid->model()->orderByDesc('id');

        $grid->disableCreateButton();
        $grid->disableColumnSelector();
//        $grid->disableRowSelector();
        $grid->expandFilter();
        $grid->disableActions();
        $grid->filter(function(Grid\Filter $filter){

            $filter->disableIdFilter();

            $filter->column(1/2, function(Grid\Filter $filter){

                $filter->equal('openid', __('Openid'));
                $filter->equal('mobile', __('Mobile'));
            });
            $filter->column(1/2, function(Grid\Filter $filter){

                $filter->between('created_at',__('Created at'))->datetime();
            });
        });

        $grid->column('id', __('Id'));
        $grid->column('active_id', __('Active id'));
        $grid->column('mobile', __('Mobile'));
        $grid->column('openid', __('Openid'));
        $grid->column('status', __('Status'));
        $grid->column('send_time', __('Send time'));
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Yuyue::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('active_id', __('Active id'));
        $show->field('mobile', __('Mobile'));
        $show->field('openid', __('Openid'));
        $show->field('status', __('Status'));
        $show->field('send_time', __('Send time'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Yuyue());

        $form->number('active_id', __('Active id'));
        $form->mobile('mobile', __('Mobile'));
        $form->text('openid', __('Openid'));
        $form->number('status', __('Status'));
        $form->number('send_time', __('Send time'));

        return $form;
    }
}
